package com.example.yuekaoceshi;



import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.yuekaoceshi.adapter.VpAdapter;
import com.example.yuekaoceshi.fragment.CollectFragment;
import com.example.yuekaoceshi.fragment.ListFragment;
import com.umeng.socialize.UMShareAPI;

import org.w3c.dom.Text;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity2 extends AppCompatActivity {

    @BindView(R.id.vp)
    ViewPager mVp;
    @BindView(R.id.tab)
    TabLayout mTab;
    ArrayList<Fragment> mFragments;
    ArrayList<String> mTitles;
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        data();

        ButterKnife.bind(this);
        initView();
    }
    private void data() {
        mFragments = new ArrayList<>();
        mFragments.add(new ListFragment());
        mFragments.add(new CollectFragment());
        mTitles = new ArrayList<>();
        mTitles.add("首页");
        mTitles.add("收藏");
    }
    private void initView() {


        VpAdapter vpAdapter = new VpAdapter(getSupportFragmentManager(),mFragments,mTitles);
        mVp.setAdapter(vpAdapter);
        mTab.setupWithViewPager(mVp);
        for (int i = 0; i <mTitles.size() ; i++) {
            View inflate = LayoutInflater.from(this).inflate(R.layout.tablayout, null, false);
            TabLayout.Tab tabAt = mTab.getTabAt(i);
            ImageView iv = inflate.findViewById(R.id.tab_iv);
            TextView tv = inflate.findViewById(R.id.tab_tv);
            tabAt.setCustomView(inflate);
            if (i==0){
                iv.setBackgroundResource(R.drawable.selector1);
            }else {
                iv.setBackgroundResource(R.drawable.selector2);
            }
            tv.setText(mTitles.get(i));
        }
    }
}
